package com.gxa.web_admin.controller.propertycontroller;

import com.gxa.common.R;
import com.gxa.modules.pojo.Car;
import com.gxa.modules.service.propertyservice.CarManageService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;


/**
 * @version 1.0
 * @Author xj
 * @Date 2022/5/6 23:57
 **/
@RestController
@RequestMapping("/CarManage")
@Api(value = "车辆信息管理",tags = "车辆信息查询接口API")
public class CarManageController {


    @Autowired(required = false)
    public R r;
    @Autowired(required = false)
    CarManageService carManageService;

    @RequestMapping(value = "/selectAllCarManageForPage",method = RequestMethod.GET)
    @ApiOperation(value = "查询车辆信息管理接口" ,notes = "提供当前页码数与每页显示条数",httpMethod = "GET",response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "当前页码数",required = true,dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "size",value = "每页显示条数", required = true,dataType = "String",paramType = "query")
    })
    @ApiResponses({
            @ApiResponse(code = 200,message = "请求成功"),
            @ApiResponse(code = 400,message = "参数格式不对"),
            @ApiResponse(code = 404,message = "找不到页面"),
            @ApiResponse(code = 500,message = "后台服务错误")
    })
    public R selectAllCarManageForPage(int page, int size)
    {
//        R r = new R();
//        r.setCode(200);
//        r.setMsg("查询成功");
//        return r;
        return carManageService.selectAllCarManageForPage( page,  size);
    }

    @RequestMapping(value = "/selectAllCarManage",method = RequestMethod.GET)
    @ApiOperation(value = "根据多种条件查询车辆信息管理接口" ,notes = "提供当前页码数与每页显示条数",httpMethod = "GET",response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "当前页码数",required = true,dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "size",value = "每页显示条数", required = true,dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "plateNumber",value = "车辆号码", required = false,dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "carModel",value = "车辆类型", required = false,dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "phone",value = "联系方式", required = false,dataType = "String",paramType = "query")
    })
    @ApiResponses({
            @ApiResponse(code = 200,message = "请求成功"),
            @ApiResponse(code = 400,message = "参数格式不对"),
            @ApiResponse(code = 404,message = "找不到页面"),
            @ApiResponse(code = 500,message = "后台服务错误")
    })
    public R selectAllCarManage(int page, int size, String plateNumber, String carModel, String phone)
    {
//        R r = new R();
//        r.setCode(200);
//        r.setMsg("查询成功");
//        return r;
        return carManageService.selectAllCarManage(page,  size,  plateNumber,  carModel,  phone);
    }


    @PostMapping("/insertCarManage")
    @ApiOperation(value = "车辆信息新增" ,notes = "提供当前页码数与每页显示条数",httpMethod = "POST",response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "根据此条件新增车辆信息",required = false,dataType = "String",paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 200,message = "请求成功"),
            @ApiResponse(code = 400,message = "参数格式不对"),
            @ApiResponse(code = 404,message = "找不到页面"),
            @ApiResponse(code = 500,message = "后台服务错误")
    })
    public R insertCarManage(@RequestBody Car car)
    {
        return carManageService.insertCarManage(car);

    }

    @RequestMapping(value = "/selectDetails", method = RequestMethod.GET)
    @ApiOperation(value = "根据id查询车辆信息接口", notes = "条件查询访客信息", httpMethod = "GET", response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "根据此条件查询车辆信息",required = true,dataType = "String",paramType = "query"),
    })

    public R selectDetails(int id) {

        return  carManageService.selectDetails(id);

    }

    @PostMapping("/deleteCarManageById")
    @ApiOperation(value = "删除车辆信息接口" ,notes = "提供当前页码数与每页显示条数",httpMethod = "POST",response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "根据此条件查询设备信息",required = true,dataType = "String",paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 200,message = "请求成功"),
            @ApiResponse(code = 400,message = "参数格式不对"),
            @ApiResponse(code = 404,message = "找不到页面"),
            @ApiResponse(code = 500,message = "后台服务错误")
    })
    public R deleteCarManageById(String id)
    {
//        R r = new R();
//        r.setCode(200);
//        r.setMsg("删除成功");
//        return r;
        return carManageService.deleteCarManageById(id);
    }

    @PostMapping("/deleteCarManage")
    @ApiOperation(value = "批量删除车辆信息接口" ,notes = "提供当前页码数与每页显示条数",httpMethod = "POST",response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "gpId",value = "根据此条件删除访客信息",required = true,dataType = "String",paramType = "query"),
    })
    public void deleteCarManage(@RequestParam(value = "gpId") String gpId) {
        String[] gpIds = gpId.split(",");
        List<Integer> list = new ArrayList<>();
        for(String str:gpIds){
            list.add(Integer.parseInt(str));
        }

        carManageService.deleteCarManage(list);
    }


    @RequestMapping(value = "/selectAllCarRecordForPage", method = RequestMethod.GET)
    @ApiOperation(value = "显示车辆进出记录表", notes = "提供当前页码数与每页显示条数", httpMethod = "GET", response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页码数", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "size", value = "每页显示条数", required = true, dataType = "int", paramType = "query")
    })
    public R selectAllVisitorRecordForPage(int page, int size) {

        return carManageService.selectAllCarRecordForPage(page, size);
    }



    @RequestMapping(value = "/selectAllCarRecord",method = RequestMethod.GET)
    @ApiOperation(value = "根据多种条件查询车辆信息管理接口" ,notes = "提供当前页码数与每页显示条数",httpMethod = "GET",response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "当前页码数",required = true,dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "size",value = "每页显示条数", required = true,dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "plateNumber",value = "车辆号码", required = false,dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "accessTime",value = "进出时间", required = false,dataType = "Data",paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 200,message = "请求成功"),
            @ApiResponse(code = 400,message = "参数格式不对"),
            @ApiResponse(code = 404,message = "找不到页面"),
            @ApiResponse(code = 500,message = "后台服务错误")
    })
    public R selectAllCarRecord(int page,int size, String plateNumber,
                                Date accessTime) {

        return  carManageService.selectAllCarRecord(page,size,plateNumber, accessTime);

    }

    /*hhh*/

    @PostMapping("/deleteCarRecordById")
    @ApiOperation(value = "删除车辆道闸报警接口" ,notes = "提供当前页码数与每页显示条数",httpMethod = "POST",response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "根据此条件查询设备信息",required = true,dataType = "String",paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 200,message = "请求成功"),
            @ApiResponse(code = 400,message = "参数格式不对"),
            @ApiResponse(code = 404,message = "找不到页面"),
            @ApiResponse(code = 500,message = "后台服务错误")
    })
    public R deleteCarRecordById(String id)
    {
//        R r = new R();
//        r.setCode(200);
//        r.setMsg("删除成功");
//        return r;
        return carManageService.deleteCarRecordById(id);
    }






}
